<?php
namespace app\index\controller;
use app\index\controller\Common;
use app\index\model\StudentStyle as StudentStyleModel;
/**
* 学生风采管理
*/
class StudentStyle extends Common
{
	
	public function index(){
		$studentRes=db('student_style')->order('id desc')->paginate(10);
		$this->assign('studentRes',$studentRes);
		return $this->fetch();
	}
	public function add(){
		if (request()->isPost()) {
			  $data=input('post.');//接受数据

            $stu=new StudentStyleModel();
            $validate = \think\Loader::validate('StudentStyle');
            if(!$validate->scene('add')->check($data)){
                $this->error($validate->getError());
            }
            if ($stu->save($data)) {
                $this->success('添加学生风采成功！',url('index'));
            }else{
                $this->error('添加学生风采失败！');
            }
            return;
		}
		return $this->fetch();
	}
	public function edit(){
		if (request()->isPost()) {
			$data=input('post.');
			
			$stu=new StudentStyleModel();
            $validate = \think\Loader::validate('StudentStyle');
            if(!$validate->scene('edit')->check($data)){
                $this->error($validate->getError());
            }
            if ($stu->update($data)) {
                $this->success('修改学生风采成功！',url('index'));
            }else{
                $this->error('修改学生风采失败！');
            }
            return;
		}
		$id=input('id');
		$stuRes=db('student_style')->where(array('id'=>$id))->find();
		$this->assign('stuRes',$stuRes);
		return $this->fetch();
	}
	public function del(){
		if(StudentStyleModel::destroy(input('id'))){
            $this->success('删除学生风采成功！',url('index'));
        }else{
            $this->error('删除学生风采失败！');
        }
	}
}